package src;

public class Student extends people {

    public Student() {
        super();
        courses = new Course[3];
    }

    public Student(int stuId, String stuName) {
        super();
        this.Id = stuId;
        this.Name = stuName;
        courses = new Course[3];
    }

    public boolean isSelectedCourse(Course course) {
        boolean flag = false;
        for (Course c : courses) {
            if (c == course) {
                flag = true;
                break;
            }
        }
        return flag;
    }

    public boolean isNullCourse(Course course) {
        boolean flag = false;
        for (Course c : courses) {
            if (c == null) {
                flag = true;
                break;
            }
        }
        return flag;

    }

    public boolean addCourse(Course course) {

        boolean flag = false;
        if (!isSelectedCourse(course) && isNullCourse(course)) {
            for (int i = 0; i < this.courses.length; i++) {
                if (courses[i] == null) {
                    courses[i] = course;

                    flag = true;
                    break;
                }
            }
        }
        return flag;
    }

    public boolean removeCourse(Course course) {
        boolean flag = false;
        if (isSelectedCourse(course)) {
            for (int i = 0; i < this.courses.length; i++) {
                if (courses[i] == course) {
                    courses[i] = null;

                    flag = true;
                    break;
                }
            }

        }
        return flag;
    }

    public void displayCourse() {
        System.out.println("学生" + this.Name + "所选课程有：");
        for (Course c : courses) {
            if (c != null) {
                System.out.println(c.getId() + " " + c.getName() + " " + c.getPlace() + " " + c.getTime() + " "
                        + c.getTeacher() + "  ");
            }
        }
        System.out.println();
    }

}
